package com.huangwenshuo.futurestarschoolmanagement.controller;

import com.huangwenshuo.futurestarschoolmanagement.exception.CustomRuntimeException;
import com.huangwenshuo.futurestarschoolmanagement.pojo.dto.UserDto;
import com.huangwenshuo.futurestarschoolmanagement.pojo.enums.RequestStateEnum;
import com.huangwenshuo.futurestarschoolmanagement.pojo.vo.Result;
import com.huangwenshuo.futurestarschoolmanagement.pojo.vo.RolesVo;
import com.huangwenshuo.futurestarschoolmanagement.service.RolesService;
import com.huangwenshuo.futurestarschoolmanagement.utils.ResUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/role")
public class RolesController {

    @Autowired
    private RolesService rolesService;

    @GetMapping("/getRoles")
    public Result getRoles(int page,int rows) {
        List<RolesVo> rolesVos = null;
        try {
             rolesVos = rolesService.getRoles(page,rows);
        } catch (CustomRuntimeException e) {
            return ResUtils.result(RequestStateEnum.FAILED.value(), "获取失败, " + e.getMessage());
        }
        return ResUtils.result(RequestStateEnum.SUCCESS.value(),rolesVos,"获取成功");
    }
    @GetMapping("/getRolesInfo")
    public Result getRolesInfo(Integer rid,int page,int rows){
        RolesVo rolesVo = null;
        try {
            rolesVo = rolesService.getRolesInfo(rid,page,rows);
        } catch (CustomRuntimeException e) {
            return ResUtils.result(RequestStateEnum.FAILED.value(), "获取失败, " + e.getMessage());
        }
        return ResUtils.result(RequestStateEnum.SUCCESS.value(),rolesVo,"获取成功");
    }




}
